package com.walterlife.dp.SingletonDP;

import java.lang.reflect.Constructor;

// @file    ReflectionSingletonTest.java
// @brief
// @author  walterzywei@gmail.com
// @version 1.0

public class ReflectionSingletonTest {
    public static void main (String [] args) {
        Singleton instanceOne = Singleton.getInstance();
        Singleton instanceTwo = null;

        try {
            Constructor[] constructors = Singleton.class.getDeclaredConstructors();
            
            for(Constructor constructor: constructors) {
                constructor.setAccessible(true);
                instanceTwo = (Singleton)constructor.newInstance();
                break;
            } 
        } catch(Exception e) {
            e.printStackTrace(); 
        }

        System.out.printf("instanceOne hashCode:%d\ninstanceTwo hashCode:%d\n", instanceOne.hashCode(), instanceTwo.hashCode());
    }         
}
